package com.zl.tesseract.scanner.greendao.services;

import com.zl.tesseract.scanner.beans.EnterBean;
import com.zl.tesseract.scanner.greendao.GreenDaoHelper;
import com.zl.tesseract.scanner.greendao.db.EnterBeanDao;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

public class EnterBeanService {

    private static EnterBeanDao fcBeanDao;

    public static void saveOne(EnterBean enterBean) {
        if(fcBeanDao == null){
            fcBeanDao = GreenDaoHelper.getDaoSession().getEnterBeanDao();
        }
        fcBeanDao.save(enterBean);
    }

    public static void saveList(List<EnterBean> list) {
        for (EnterBean blastDicBean : list) {
            saveOne(blastDicBean);
        }
    }

    public static List<EnterBean> findAll() {
        if(fcBeanDao == null){
            fcBeanDao = GreenDaoHelper.getDaoSession().getEnterBeanDao();
        }
        return fcBeanDao.loadAll();
    }

    public static EnterBean findOneByOrderId(String order_id) {
        if(fcBeanDao == null){
            fcBeanDao = GreenDaoHelper.getDaoSession().getEnterBeanDao();
        }
        QueryBuilder<EnterBean> queryBuilder = fcBeanDao.queryBuilder();
        return queryBuilder.where(EnterBeanDao.Properties.Order_id.eq(order_id)).unique();
    }

    public static void deleteOne(EnterBean blastDicBean) {
        if(fcBeanDao == null){
            fcBeanDao = GreenDaoHelper.getDaoSession().getEnterBeanDao();
        }
        fcBeanDao.delete(blastDicBean);
    }

    public static void deleteAll() {
        if(fcBeanDao == null){
            fcBeanDao = GreenDaoHelper.getDaoSession().getEnterBeanDao();
        }
        fcBeanDao.deleteAll();
    }
}